package com.java2207.group1.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName : DateUtil
 * @Author : glls
 * @Date: 2022/2/25 15:47
 * @Description :  日期类型(Date)和字符串(String)互相转换的工具类
 */
public class DateUtil {

    public static Date strToDate(String str,String pattern){
        DateFormat dateFormat = new SimpleDateFormat(pattern);

        Date parse = null;
        try {
            parse = dateFormat.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return parse;
    }

    public static String dateToStr(Date date,String pattern){
        
        DateFormat dateFormat = new SimpleDateFormat(pattern);
        
        String format = dateFormat.format(date);

        return format;
    }
}
